package com.os.opencv.java.chapter7;

import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;

public class Erode2 {

    public static void main(String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        //构建一个6*6的小矩阵并导入数据
        Mat src = new Mat(6,6, CvType.CV_8UC1);
        byte[] data = new byte[]{
                0,0,0,0,0,0,
                0,0,1,1,1,0,
                0,1,1,1,1,0,
                0,1,1,0,0,0,
                0,1,1,1,0,0,
                0,0,1,1,0,0
        };
        src.put(0,0,data);

        //在控制台输出矩阵，以便进行数据确认
        System.out.println(src.dump());
        System.out.println();

        //构建十字形结构元素
        Mat kernel = Imgproc.getStructuringElement(1, new Size(3,3));
        Mat dst = new Mat(6,6,CvType.CV_8UC1);

        //进行腐蚀操作并输出腐蚀后的矩阵
        Imgproc.erode(src, dst, kernel);
        System.out.println(dst.dump());


    }
}
